//
//  CFuncPrimmer.c
//  CProject
//
//  Created by 黄小刚 on 2018/9/6.
//  Copyright © 2018年 黄小刚. All rights reserved.
//

#include "CFuncPrimmer.h"
#include <stdlib.h>
#include <string.h>

// 定义一个函数指针
int (*fptr1) (int);

// 定义一个函数指针
typedef int (*myFuncptr) (int);

// 定义一个乘法函数
int square(int num) {
    
    return num * num;
}


void testDemo (void) {
    int i = 10;
    // 给函数指针赋值
    fptr1 = square;
    // 调用函数指针
    printf("%d square is %d \n",i,fptr1(i));
    
    int n = 20;
    myFuncptr  fptr2;
    fptr2 = square;
    printf("%d squared is == %d \n",n,fptr2(n));
}

char * trim(char* phrase) {
    
    char* old = phrase;
    char* new = phrase;
    
    char *s = "aaaabbb";
    while (*s == 'a') {
        printf("%s\n",s++);
    }
    
    
    
    while (*old == ' ') {
        printf("%s\n",old++);
    }
    
    while (*old) {
        *(new++) = *(old++);
    }
    *new = 0;
    return (char *) realloc(phrase,strlen(phrase) + 1);
}

void testDemo0 (void) {
    
    char* word = (char *)malloc(strlen("      cat")+1);
    // 给分配的内存初始化
    strcpy(word,"      cat");
    printf("%s\n",trim(word));
}

void funcPrimter(void) {
    
    testDemo0();
    
}
